package com.thinkingcoder.tccache.core;

import java.util.LinkedHashMap;
import java.util.Map;

import com.thinkingcoder.tccache.core.command.Command;
import com.thinkingcoder.tccache.core.command.common.CommandCmd;
import com.thinkingcoder.tccache.core.command.common.InfoCmd;
import com.thinkingcoder.tccache.core.command.common.PingCmd;
import com.thinkingcoder.tccache.core.command.hash.HDelCmd;
import com.thinkingcoder.tccache.core.command.hash.HExistsCmd;
import com.thinkingcoder.tccache.core.command.hash.HGetAllCmd;
import com.thinkingcoder.tccache.core.command.hash.HGetCmd;
import com.thinkingcoder.tccache.core.command.hash.HLenCmd;
import com.thinkingcoder.tccache.core.command.hash.HMGetCmd;
import com.thinkingcoder.tccache.core.command.hash.HSetCmd;
import com.thinkingcoder.tccache.core.command.list.LIndexCmd;
import com.thinkingcoder.tccache.core.command.list.LLenCmd;
import com.thinkingcoder.tccache.core.command.list.LPopCmd;
import com.thinkingcoder.tccache.core.command.list.LPushCmd;
import com.thinkingcoder.tccache.core.command.list.LRangeCmd;
import com.thinkingcoder.tccache.core.command.list.RPopCmd;
import com.thinkingcoder.tccache.core.command.list.RPushCmd;
import com.thinkingcoder.tccache.core.command.set.SAddCmd;
import com.thinkingcoder.tccache.core.command.set.SCardCmd;
import com.thinkingcoder.tccache.core.command.set.SIsMemberCmd;
import com.thinkingcoder.tccache.core.command.set.SMembersCmd;
import com.thinkingcoder.tccache.core.command.set.SPopCmd;
import com.thinkingcoder.tccache.core.command.set.SRemCmd;
import com.thinkingcoder.tccache.core.command.string.DecrCmd;
import com.thinkingcoder.tccache.core.command.string.DelCmd;
import com.thinkingcoder.tccache.core.command.string.ExistsCmd;
import com.thinkingcoder.tccache.core.command.string.GetCmd;
import com.thinkingcoder.tccache.core.command.string.IncrCmd;
import com.thinkingcoder.tccache.core.command.string.MGetCmd;
import com.thinkingcoder.tccache.core.command.string.MSetCmd;
import com.thinkingcoder.tccache.core.command.string.SetCmd;
import com.thinkingcoder.tccache.core.command.string.StrLenCmd;
import com.thinkingcoder.tccache.core.command.zset.ZAddCmd;
import com.thinkingcoder.tccache.core.command.zset.ZCardCmd;
import com.thinkingcoder.tccache.core.command.zset.ZCountCmd;
import com.thinkingcoder.tccache.core.command.zset.ZRankCmd;
import com.thinkingcoder.tccache.core.command.zset.ZRemCmd;
import com.thinkingcoder.tccache.core.command.zset.ZScoreCmd;

/**
 * register all command.
 */
public class Commands {

    private static Map<String, Command> ALL = new LinkedHashMap<>();

    static {
        initCommands();
    }

    private static void initCommands() {
        // common commands
        // ping command info
        register(new PingCmd());
        register(new CommandCmd());
        register(new InfoCmd());

        // string
        // set get mset mget incr decr exists strlen del
        register(new SetCmd());
        register(new GetCmd());
        register(new MSetCmd());
        register(new MGetCmd());
        register(new IncrCmd());
        register(new DecrCmd());
        register(new ExistsCmd());
        register(new StrLenCmd());
        register(new DelCmd());

        // list
        // lpush lpop llen lindex lrange
        // rpush rpop
        register(new LPushCmd());
        register(new LPopCmd());
        register(new LLenCmd());
        register(new LIndexCmd());
        register(new LRangeCmd());
        register(new RPushCmd());
        register(new RPopCmd());

        // set
        // sadd smembers scard sismember srem spop
        register(new SAddCmd());
        register(new SMembersCmd());
        register(new SCardCmd());
        register(new SIsMemberCmd());
        register(new SRemCmd());
        register(new SPopCmd());

        // hash
        // hset hget hlen hgetall hdel hexists hmget
        register(new HSetCmd());
        register(new HGetCmd());
        register(new HLenCmd());
        register(new HGetAllCmd());
        register(new HDelCmd());
        register(new HExistsCmd());
        register(new HMGetCmd());

        // zset
        // zadd zcard zscore zrem zrank zcount
        register(new ZAddCmd());
        register(new ZCardCmd());
        register(new ZScoreCmd());
        register(new ZRemCmd());
        register(new ZRankCmd());
        register(new ZCountCmd());
    }

    public static void register(Command command) {
        ALL.put(command.name(), command);
    }

    public static Command get(String name) {
        return ALL.get(name);
    }

    public static String[] getCommandNames() {
        return ALL.keySet().toArray(new String[0]);
    }

}
